#include <linux/i2c.h>
#include <linux/module.h>
#include <linux/mod_devicetable.h>
#include <linux/platform_device.h>

static enum device_list {
    my_mouse,
    my_keyboard,
    my_sensor
};

const static struct of_device_id my_of_device_table[] = {
    [my_mouse] = {
        .compatible = "of_screen"},
    {}};

const static struct i2c_device_id my_device_id_table[] = {

    [my_mouse] = {
        .name = "my_mouse",
        .driver_data = my_mouse},

    [my_keyboard] = {.name = "my_keyboard", .driver_data = my_keyboard},

    [my_sensor] = {.name = "my_sensor", .driver_data = my_sensor},
    {}

};

int my_probe(struct i2c_client *client);

void my_remove(struct i2c_client *client);

int my_probe(struct i2c_client *client)
{
    pr_info("successfully probe my virtual i2c device\n");

    const struct of_device_id *my_of_device_id = i2c_of_match_device(my_of_device_table, client);

    if (my_of_device_id)
    {

        pr_info("by of_device_id method, compatible is %s\n", my_of_device_id->compatible);
    }
    else
    {
        pr_info("by traditional method");
    }
    return 0;
}

void my_remove(struct i2c_client *client)
{
}

static struct i2c_driver my_driver = {

    .probe = my_probe,
    .remove = my_remove,
    .driver = {
        .name = "i2c_driver"},

    .id_table = my_device_id_table};

MODULE_DEVICE_TABLE(i2c, my_device_id_table);

module_i2c_driver(my_driver);

MODULE_LICENSE("Dual BSD/GPL");
MODULE_AUTHOR("luojunhua");
MODULE_VERSION("V1.0");
